home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-20 | 4.7 KB | 188 lines | [TEXT/KAHL] |
- /******************************************************************************
- CLabeledGroup.c
-
- A class to manage a radiogroup, except that there is a title (like in
- MacApp clusters).
-
- SUPERCLASS = CRadioGroupPane
-
- Copyright © 1991 Bowers Development Corporation. All rights reserved.
-
- ******************************************************************************/
-
- #include <TBUtilities.h>
- #include <CPaneBorder.h>
- #include "CAMIconPane.h"
- #include "CLabeledGroup.h"
-
- #define kLabelIndent 12
- #define kLabelMargin 4
-
- #define LINEHEIGHT(f) ((f.ascent) + (f.descent) + (f.leading))
-
- /*----------*/
- void CLabeledGroup::ILabeledGroup (CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- short aThickness,
- short aDropShadow,
- Str255 aLabel,
- short aTextStyle,
- short aTextSize,
- Str255 aFontName)
- {
- StylesRec styles;
-
- theLabel = NULL;
-
- CRadioGroupPane::IRadioGroupPane (anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl,
- aHSizing, aVSizing);
-
- styles.textStyle = aTextStyle;
- styles.textSize = aTextSize;
- CopyPString (aFontName, styles.fontName);
- ILabeledGroupX (aThickness, aDropShadow, aLabel, &styles);
-
- } /* ILabeledGroup */
-
- /*----------*/
- void CLabeledGroup::IViewTemp (CView *anEnclosure,
- CBureaucrat *aSupervisor,
- Ptr viewData)
- {
- register CLabeledGroupTempP p;
- short strSize;
- StylesP stylesPtr;
-
- theLabel = NULL;
-
- p = (CLabeledGroupTempP) viewData;
- inherited::IViewTemp (anEnclosure, aSupervisor, (Ptr)&p->sRadioGroupPaneTemp);
- strSize = 1 + p->label [0];
- strSize += (strSize & 1); // bump to even number
- stylesPtr = (StylesP) &p->label [strSize];
- ILabeledGroupX (p->thickness, p->dropShadow, p->label, stylesPtr);
-
- } /* IViewTemp */
-
- /*----------*/
- void CLabeledGroup::ILabeledGroupX (short aThickness,
- short aDropShadow,
- Str255 aLabel,
- StylesP p)
- {
- /* do no additional initialization if there is no label. */
-
- if (aLabel [0] != 0) {
- theLabel = NewString (aLabel);
- AMSetupTextEnvirons (this, p);
- MakeBorder (aThickness, aDropShadow);
- }
- radioStation = NULL;
-
- } /* ILabeledGroupX */
-
- /*----------*/
- void CLabeledGroup::Dispose (void)
- {
- if (theLabel != NULL) {
- DisposHandle ((Handle)theLabel);
- theLabel = NULL;
- }
- inherited::Dispose ();
-
- } /* Dispose */
-
- /*----------*/
- void CLabeledGroup::MakeBorder (short aThickness,
- short aDropShadow)
- {
- CPaneBorder *border;
- Rect margin;
- FontInfo fInfo;
-
- border = new (CPaneBorder);
- border->IPaneBorder (kBorderFrame);
-
- Prepare ();
- GetFontInfo (&fInfo);
-
- SetRect (&margin, 0, LINEHEIGHT (fInfo) / 2, 0, 0);
- border->SetMargin (&margin);
- border->SetPenSize (aThickness, aThickness);
- if (aDropShadow > 0) {
- border->SetShadow (2, 2, aThickness, aThickness); /* ?? */
- }
- SetBorder (border);
-
- } /* MakeBorder */
-
- /*----------*/
- void CLabeledGroup::Draw (Rect *area)
- {
- Rect labelRect;
- FontInfo fInfo;
- short sWidth;
- short vLoc;
- Str255 labelStr;
-
- /* if there is no label, do nothing. */
-
- if (theLabel != NULL) {
- HLock ((Handle)theLabel);
- CopyPString(&(**theLabel), labelStr); /* use local variable. */
- HUnlock ((Handle)theLabel);
-
- GetFontInfo (&fInfo);
- sWidth = StringWidth (labelStr);
-
- labelRect.top = 0;
- labelRect.left = kLabelIndent;
- labelRect.right = labelRect.left + kLabelMargin + sWidth + kLabelMargin;
- labelRect.bottom = LINEHEIGHT (fInfo);
- EraseRect (&labelRect);
-
- /* move to the text baseline, which is top of rectangle - font ascent. */
- vLoc = fInfo.ascent;
- MoveTo (kLabelIndent + kLabelMargin, vLoc);
- DrawString (labelStr);
- }
-
- } /* Draw */
-
- /******************************************************************************
- ProviderChanged
-
- Respond to a change in a provider. The only provider this class
- knows about is CAMIconPane. When it receives notification that
- a radio control has been selected, the CLabeledGroup turns off
- the previously selected icon and updates the radioStation
- instance variable to refer to the newly selected icon.
- ******************************************************************************/
-
- void CLabeledGroup::ProviderChanged (CCollaborator *aProvider,
- long reason,
- void *info)
- {
- if (member (aProvider, CAMIconPane))
- {
- if ((reason == radioChanged) && ((*(Boolean*)info) == TRUE))
- {
- if (radioStation != NULL) {
- radioStation->SetRadio (FALSE);
- }
- radioStation = (CAMIconPane*) aProvider;
- }
- }
- inherited::ProviderChanged (aProvider, reason, info);
-
- } /* ProviderChanged */
-
- /* CLabeledGroup */
-